package com.core.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.core.managers.LoginManager;


public class Login
        extends TaskTrackerServlet {

	/**
     * 
     */
	private static final long serialVersionUID = 1L;



	@Override
	protected void doPost ( HttpServletRequest request,
	                        HttpServletResponse response )
	        throws ServletException, IOException {


		String userName = request.getParameter("userName");
		String userPassword = request.getParameter("userPassword");
		LoginManager loginManager = LoginManager.sharedInstance();
		loginManager.resetLoginformOpenAttepts();

		loginManager.performUserCheck(userName, userPassword);


		loginManager.doDefaultRedirection(request, response);

	}



	@Override
	protected void doGet ( HttpServletRequest request,
	                       HttpServletResponse response )
	        throws ServletException, IOException {

		LoginManager loginManager = LoginManager.sharedInstance();
		loginManager.setValidUser(false);
		loginManager.setLoginFormDisplaying(false);
		loginManager.setLoginGetMethodExecuted(true);

		super.doGet(request, response);

	}



	@Override
	protected String userContext () {

		return "LOGIN";
	}



}
